package cn.hbwe.service.impl;

import cn.hbwe.pojo.dto.PayDto;
import cn.hbwe.pojo.entity.Doctor;
import cn.hbwe.pojo.entity.Patient;
import cn.hbwe.pojo.entity.Pay;
import cn.hbwe.mapper.PayMapper;
import cn.hbwe.pojo.entity.Schedule;
import cn.hbwe.service.IDoctorService;
import cn.hbwe.service.IPatientService;
import cn.hbwe.service.IPayService;
import cn.hbwe.service.IScheduleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 7组
 * @since 2023-10-18
 */
@Service
public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayService {

    @Autowired
    private IDoctorService doctorService;

    @Autowired
    private IPatientService patientService;

    @Autowired
    private IScheduleService iScheduleService;

    /**
     * 支付功能
     * @param payDto
     * @return
     */
    @Override
    public void pay(PayDto payDto) {
        Integer doctorId = payDto.getDoctorId();
        Doctor doctor = doctorService.getById(doctorId);
        Integer patientId = payDto.getPatientId();
        Patient patient = patientService.getById(patientId);
        //创建实体类,添加
        Pay pay = new Pay();
        pay.setDoctorId(doctorId);
        pay.setPatientId(patientId);
        pay.setBookingId(payDto.getBookingId());
        pay.setPayName(doctor.getDoctorName() + ":" + patient.getPatientName());
        pay.setPrice(doctor.getPrice());
        pay.setStatus("已支付");

        this.save(pay);
    }
}
